package com.momo.points.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    public boolean setEx(String key,String value,Long expire){
        stringRedisTemplate.opsForValue().set(key,value,expire);
        return stringRedisTemplate.expire(key,expire, TimeUnit.SECONDS);
    }

    public boolean exits(String key){
       return stringRedisTemplate.hasKey(key);
    }

    public boolean delete(String key){
        if (exits(key)) {
            stringRedisTemplate.delete(key);
        }
        return false;
    }
}
